<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="../templates/header_common::header_common(~{::title},~{::link})">
    <meta charset="UTF-8">
    <title>用户页面</title>
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/base.css}">
</head>
<body ng-app="shop" ng-controller="userController">
<h1>haoren</h1>
<input ng-model="id">
<button ng-click="queryById()">加载数据</button>
</br>
<input ng-model="name">
<button ng-click="queryUsersByLikeName()">加载多个数据</button>
</body>
<script>
    var shop = angular.module("shop", ["ngResource"]);
    shop.service("userServices", function ($resource) {
        //创建资源对象
        let userServices = $resource('/user/:id', {id: '@id'});
        this.loadUserById = function (id) {
            return userServices.get({id: id});
        }
        this.loadUsersByLikeName = function (name) {
            return $resource('/user/like/:name').query({name: name});
        }
    });
    shop.controller("userController", function ($scope, userServices) {
        $scope.queryById = function () {
            userServices.loadUserById($scope.id).$promise.then(function success(response) {
                console.log(response);
            });
        }
        $scope.queryUsersByLikeName = function () {
            userServices.loadUsersByLikeName($scope.name).$promise.then(function success(response) {
                console.log(response);
            });
        }
    });
</script>
</html>